using System.Collections.Generic;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Styling;
using LuckyFish.CalculatorApp.Controls;

namespace LuckyFish.CalculatorApp;

public partial class MainWindow : Window
{
    private Dictionary<string, Control> Stack { get; set; }

    public MainWindow()
    {
        Stack = new Dictionary<string, Control>()
        {
            { "Calculator", new CalculatorControl() }
        };
        InitializeComponent();
        var app = Application.Current?.ActualThemeVariant;
        Background = app == ThemeVariant.Dark
            ? new SolidColorBrush(Color.Parse("#292421"))
            : new SolidColorBrush(Color.Parse("#f3f5f7"));
        StackPanel.Background = app == ThemeVariant.Dark
            ? new SolidColorBrush(Color.Parse("#292421"))
            : new SolidColorBrush(Color.Parse("#f3f5f7"));
        ChangeItem("Calculator");
    }

    private void ChangeItem(string? s)
    {
        if (!Stack.TryGetValue(s ?? "", out var control)) return;
        ContentControl.Content = control;
    }

    private void MenuClick(object? sender, RoutedEventArgs e)
    {
        ItemPanel.IsVisible = !ItemPanel.IsVisible;
    }

    private void ItemClick(object? sender, RoutedEventArgs e)
    {
        if (sender is not Control control) return;
        ChangeItem(control.Tag as string);
    }
}